/*
 * @Author: zi.yang
 * @Date: 2021-10-04 23:31:14
 * @LastEditors: zi.yang
 * @LastEditTime: 2021-10-04 23:52:22
 * @Description: In User Settings Edit
 * @FilePath: \project-management\services\SysDictData.js
 */
const SysDictData = require('../models/sys_dict_data');

/**
 * @description: 获取所有字典
 * @param { function } cb
 * @return: cb()
 */
exports.findAllDictData = async (cb) => {
  try {
    const dictData = await SysDictData.findAll();
    return cb({ code: 200, msg: 'success', data: dictData });
  } catch (e) {
    console.log(e);
    return cb({ code: 500, msg: 'error', data: [] });
  }
}

/**
 * @description 根据字典类型获取字典
 * @param { String } dictType 
 * @param { Function } cb 
 * @returns 
 */
exports.findDictDataByDictType = async (dictType,cb) => {
  try {
    const dictData = await SysDictData.findAndCount({ where: dictType });
    return cb({ code: 200, msg: 'success', data: dictData });
  } catch (e) {
    console.log(e);
    return cb({ code: 500, msg: 'error', data: [] });
  }
}